#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.



import requests
import json
import uuid

url = "http://SERVER_HOST_IP:12021/cluster/createRayCluster"

def get_request_id():
    return str(uuid.uuid1())

request_id = get_request_id()
print('Create ray cluster request id: %s '  % request_id)

data = {
    "RequestId": request_id,
    "ClusterName": "ray-cluster-test",
    "KubeConfPath": "/root/.kube/config",
    "Namespace": "default",
    "HeadNode": {
        "Image": "xxx-vpc.cn-hangzhou.cr.aliyuncs.com/fce/ray:v2.31.0-py311-cpu",
        "Cpu": 2,
        "Memory": "4G",
        "NodeAffinity": [
            {
                "Key": "ray.clusterId",
                "Operator": "In",
                "Values": [ "ray-cluster-test" ]
            },
        ],
        "EnvironmentVars": [
            { 
                "Name": "TEST_ENV",
                "Value": "testing value",
            },
            { 
                "Name": "PIP_INDEX_URL",
                "Value": "testing recover",
            }
        ],
    },
    #TBD:only support one worker node group currently
    "WorkerNodeGroups": [
        {
            "Image": "xxx-registry-vpc.cn-hangzhou.cr.aliyuncs.com/fce/fusion-engine:ray_v2.31.0",
            "Cpu": 2,
            "Memory": "4G",
            "Replicas": 2,
            "NodeAffinity": [
                {
                    "Key": "ray.clusterId",
                    "Operator": "In",
                    "Values": [ "ray-cluster-test" ]
                },
            ],
            "EnvironmentVars": [
                { 
                    "Name": "TEST_ENV2",
                    "Value": "testing value2",
                },
                { 
                    "Name": "PIP_INDEX_URL",
                    "Value": "testing recover2",
                }
            ],
        },
    ]
}

response = requests.post(url, json=data, verify=False)

if response.status_code == 200:
    received_data = response.json()
    print("Received data:", received_data)
else:
    print("Request failed with status code:", response.status_code)
